package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.bean.StarsBean;
import flc.ast.databinding.ActivityQueryResultBinding;
import stark.common.basic.event.EventStatProxy;

public class QueryResultActivity extends BaseAc<ActivityQueryResultBinding> {

    public static int m, d;
    private List<StarsBean> listStar = new ArrayList<>();
    private int starPos;

    @Override
    protected int onCreate() {
        return R.layout.activity_query_result;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(this, mDataBinding.event5Container);

        mDataBinding.ivQueryResultBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvResultName.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvResultName:
                StarDetailActivity.starsBean = listStar.get(starPos);
                startActivity(StarDetailActivity.class);
                break;
        }
    }

    @Override
    protected void initData() {
        getData();
        if ((m == 3 && d > 20) || (m == 4) && d < 21) {
            starPos = 0;
        } else if ((m == 4 && d > 20) || (m == 5 && d < 21)) {
            starPos = 1;
        } else if ((m == 5 && d > 20) || (m == 6 && d < 22)) {
            starPos = 2;
        } else if ((m == 6 && d > 21) || (m == 7 && d < 23)) {
            starPos = 3;
        } else if ((m == 7 && d > 22) || (m == 8 && d < 23)) {
            starPos = 4;
        } else if ((m == 8 && d > 22) || (m == 9 && d < 23)) {
            starPos = 5;
        } else if ((m == 9 && d > 22) || (m == 10 && d < 23)) {
            starPos = 6;
        } else if ((m == 10 && d > 22) || (m == 11 && d < 22)) {
            starPos = 7;
        } else if ((m == 11 && d > 21) || m == 12 && d < 22) {
            starPos = 8;
        } else if ((m == 12 && d > 21) || (m == 1 && d < 20)) {
            starPos = 9;
        } else if ((m == 1 && d > 19) || (m == 2 && d < 19)) {
            starPos = 10;
        } else if ((m == 2 && d > 18 || (m == 3 && d < 21))) {
            starPos = 11;
        }
        mDataBinding.ivResultImg.setImageResource(listStar.get(starPos).getImg());
        mDataBinding.tvResultName.setText(listStar.get(starPos).getName());
        mDataBinding.tvResultBirthDate.setText(listStar.get(starPos).getDate());
    }

    private void getData() {
        listStar.add(new StarsBean(getString(R.string.star_sign1), R.drawable.aimg_xz1_by, getString(R.string.birth_date1)));
        listStar.add(new StarsBean(getString(R.string.star_sign2), R.drawable.aimg_xz1_jn, getString(R.string.birth_date2)));
        listStar.add(new StarsBean(getString(R.string.star_sign3), R.drawable.aimg_xz1_sz2, getString(R.string.birth_date3)));
        listStar.add(new StarsBean(getString(R.string.star_sign4), R.drawable.aimg_xz1_jx, getString(R.string.birth_date4)));
        listStar.add(new StarsBean(getString(R.string.star_sign5), R.drawable.aimg_xz1_sz, getString(R.string.birth_date5)));
        listStar.add(new StarsBean(getString(R.string.star_sign6), R.drawable.aimg_xz1_cn, getString(R.string.birth_date6)));
        listStar.add(new StarsBean(getString(R.string.star_sign7), R.drawable.aimg_xz1_tc, getString(R.string.birth_date7)));
        listStar.add(new StarsBean(getString(R.string.star_sign8), R.drawable.aimg_xz1_tx, getString(R.string.birth_date8)));
        listStar.add(new StarsBean(getString(R.string.star_sign9), R.drawable.aimg_xz1_ss, getString(R.string.birth_date9)));
        listStar.add(new StarsBean(getString(R.string.star_sign10), R.drawable.aimg_xz1_mx, getString(R.string.birth_date10)));
        listStar.add(new StarsBean(getString(R.string.star_sign11), R.drawable.aimg_xz1_sp, getString(R.string.birth_date11)));
        listStar.add(new StarsBean(getString(R.string.star_sign12), R.drawable.aimg_xz1_sy, getString(R.string.birth_date12)));
    }

}